package com.qf.tenant.manager.api;

import com.qf.common.bean.R;
import com.qf.common.dto.CmdParamDto;
import com.qf.tenant.manager.service.CmdService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 千锋健哥
 */
@RestController
@RequestMapping("/tenant/cmd")
public class CmdController {

    @Autowired
    private CmdService cmdService;

    @PostMapping("/send")
    public R sendCmd(@RequestBody CmdParamDto dto) {
        if (dto == null) {
            return R.fail("参数不能为空!");
        }
        if (StringUtils.isEmpty(dto.getDeviceKey())
            || StringUtils.isEmpty(dto.getCmdName())
            || StringUtils.isEmpty(dto.getValue())) {
            return R.fail("设备key, 指令名称, 指令值都不可以为空!");
        }
        R result = cmdService.send(dto);
        return result;
    }
}
